/**
 * 
 */
package com.ynet.middleground.riskmanage.service.impl;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.cangdan.QueryCangDanFreezeReq;
import com.ynet.middleground.riskmanage.bean.cangdan.QueryCangDanTransferReq;
import com.ynet.middleground.riskmanage.dto.cangdan.QueryCangDanFreezeDTO;
import com.ynet.middleground.riskmanage.dto.cangdan.QueryCangDanTransferDTO;
import com.ynet.middleground.riskmanage.model.CangDanModel;
import com.ynet.middleground.riskmanage.service.CangDanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * @ClassName CangDanServiceImpl
 * @Description 对接电子仓单服务实现类
 * @Author songyf
 * @Date 2022/11/28
 * @Version 1.0
 */

@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Api(value = "对接电子仓单服务实现类", tags = {"对接电子仓单服务实现类"})
@Path("cangdan")
@Service(timeout = 6000, version = "0.0.1")
public class CangDanServiceImpl implements CangDanService, GenericService {
    @Autowired
    CangDanModel cangDanModel;

    @POST
    @Path("query-freeze")
    @ApiOperation(value = "查询电子仓单冻结/解冻指令", notes = "查询电子仓单冻结/解冻指令",hidden = true)
    @ApiImplicitParam(name = "requestObj", dataType = "QueryCangDanFreezeReq", paramType = "body",
            required = true)
    @Override
    public ServiceResult<List<QueryCangDanFreezeDTO>> queryCangDanFreeze(QueryCangDanFreezeReq requestObj) {
        ServiceResult<List<QueryCangDanFreezeDTO>> result = new ServiceResult<>();
        try {
            result.setResult(cangDanModel.queryCangDanFreeze(requestObj));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "查询电子仓单冻结/解冻指令服务异常, case: {}",
                    Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    @POST
    @Path("query-transfer")
    @ApiOperation(value = "查询电子仓单转让指令", notes = "查询电子仓单转让指令",hidden = true)
    @ApiImplicitParam(name = "requestObj", dataType = "QueryCangDanTransferReq", paramType = "body",
            required = true)
    @Override
    public ServiceResult<List<QueryCangDanTransferDTO>> queryCangDanTransfer(QueryCangDanTransferReq requestObj) {
        ServiceResult<List<QueryCangDanTransferDTO>> result = new ServiceResult<>();
        try {
            result.setResult(cangDanModel.queryCangDanTransfer(requestObj));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "查询电子仓单转让指令服务异常, case: {}",
                    Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }
}
